package com.test;

import java.awt.Component;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JComponent;
import javax.swing.JPanel;

import org.apache.log4j.Logger;

public class GLManager {

	static Logger logger = Logger.getLogger(DiskSpaceUsed.class);
	static final int CHILDLESS = 3;
	/**
	 * Relayout all JPanel.
	 * @param component
	 * @param child true if this is the JPanel containing children
	 * @throws Exception
	 */
	public static void traverseComponents(JComponent component, boolean child) throws Exception {
		Component[] components=component.getComponents();
		List<JPanel> jpanels=new ArrayList<JPanel>();
		for (int i = 0; i < components.length; i++) {
			Component c = components[i];
			if (c instanceof JPanel) {
				JPanel jp=(JPanel) c;
				jpanels.add(jp);
				if (components.length>CHILDLESS||!child) traverseComponents(jp, !child);
				logger.debug("Traversing component "+jp.getName()+" as a "+(child?"child":"parent")+"\n");
			}
		}
		if (child) relayout(component, jpanels);
	}
	
	public static void relayout(JComponent childContainer, List<JPanel> jpanels) {
		logger.debug("About to layout children of "+childContainer.getName()+"\n");
	}
}
